package com.test.exam.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJacksonJsonView;

import com.test.exam.domain.Student;
import com.test.exam.service.StudentService;

@Controller
//비동기 요청을 처리하는 Controller
public class AjaxController {
	@Autowired
	private StudentService studentService;
	
	// home.jsp 학생 목록 받는 ... 
	@RequestMapping(value="/student/ajax/getStudentsByBanIdx"
					)
	public ModelAndView getStudentsByBanIdx(@RequestParam int banIdx){
		
		List<Student> list = studentService.getStudentsByBanIdx(banIdx);
		//	System.out.println("ajax 요청...");
		ModelAndView modelAndView = 
				new ModelAndView(new MappingJacksonJsonView());
		modelAndView.addObject(list);
		return modelAndView;
	}

}






